package com.spc.car.data.domain.project.po;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.data.entity.project.ProjectTeam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ProjectTeamQueryPO {

    /**
     * 招标项目编号
     */
    @NotBlank(message = "招标项目编号不能为空")
    private String projectTenderingCode;

    /**
     * 权限 多权限采用逗号分隔
     */
    private String permissions;

    private boolean showCollaborator = true;

    public Wrapper toWrapper() {
        QueryWrapper<ProjectTeam> condition = new QueryWrapper<>();
        condition.eq(StringUtils.isNotBlank(projectTenderingCode),
                "project_tendering_code" , projectTenderingCode);
        condition.orderByAsc("id");

        return condition;
    }

    public List<String> listPermission() {
        List<String> permissionList = new ArrayList<>();
        if (StringUtils.isNotBlank(this.permissions)) {
            permissionList = Arrays.asList(this.permissions.split(","));
        }
        return permissionList;
    }

}
